home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / anides32 / example.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-12-16  |  3.8 KB  |  105 lines

  1. /************************************************************
  2.  Example.c - Source file to show how to use with AniDes32.dll
  3.  Created by Wong Siu Wai, December 1997.
  4.  ************************************************************/
  5.  
  6. /*You must link the AniDes32.lib import library to the make file.
  7.   For example, click <Build> in the menu and then click <Setting> for 
  8.   Visual C++, change the link property by adding AniDes32.lib
  9.   in the edit box.*/
  10.  
  11. #include <windows.h>
  12. #include <stdlib.h>
  13. #include "AniDes32.h" //Must be included for using AniDes32.dll
  14.  
  15. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  16.  
  17. int FAR PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  18.                               LPSTR szCmdLine, int iCmdShow)
  19.     {
  20.     static char szAppName[] = "Example";
  21.     WNDCLASSEX wc;
  22.     HWND hwnd;
  23.     MSG msg;
  24.  
  25.     wc.cbSize        = sizeof(wc);
  26.     wc.style         = CS_HREDRAW | CS_VREDRAW;
  27.     wc.lpfnWndProc   = WndProc;
  28.     wc.cbClsExtra    = 0;
  29.     wc.cbWndExtra    = 0;
  30.     wc.hInstance     = hInstance;
  31.     wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  32.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  33.     wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  34.     wc.lpszMenuName  = NULL;
  35.     wc.lpszClassName = szAppName;
  36.     wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
  37.  
  38.     RegisterClassEx(&wc);
  39.  
  40.     hwnd = CreateWindow(szAppName, szAppName,
  41.                               WS_POPUP, 0, 0, //Use Popup as a full screen window
  42.                               GetSystemMetrics(SM_CXSCREEN), //Get the x-axis screen
  43.                               GetSystemMetrics(SM_CYSCREEN), //Get the y-axis screen
  44.                               NULL, NULL, hInstance, NULL);
  45.  
  46.     while(!SetTimer(hwnd, 1, 1000, NULL)) /*Set timer for keep on updating the window, 
  47.    set it by no more that 1 min, must be included also.*/
  48.         {
  49.         if(IDCANCEL == MessageBox(hwnd, "Too many clocks or timers",
  50.             szAppName, MB_ICONEXCLAMATION | MB_RETRYCANCEL))
  51.             return FALSE;
  52.         }
  53.  
  54.     while(GetMessage(&msg, NULL, 0, 0))
  55.         {
  56.         TranslateMessage(&msg);
  57.         DispatchMessage(&msg);
  58.         }
  59.  
  60.     return msg.wParam;
  61.     }
  62.  
  63. LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
  64.                                  WPARAM wParam, LPARAM lParam)
  65.     {
  66.     int    i, xStart, yStart, xEnd, yEnd, iColor[2];
  67.     static HRGN hRgn;
  68.     TEXTMETRIC tm;
  69.     RECT rect;
  70.     HDC hdc;
  71.  
  72.     switch(message)
  73.         {
  74.         case WM_TIMER:
  75.               for(i = 0; i <= 2; i++)
  76.                   iColor[i] = rand() % 255; 
  77.               hdc = SetDisplayDC(); //Call function SetDisplayDC() to get the dislapy DC
  78.               GetClientRect(hwnd, &rect); //Get the client rect, now is same as the screen
  79.               GetTextMetrics(hdc, &tm);
  80.               xStart = (GetSystemMetrics(SM_CXSCREEN) -
  81.                           tm.tmAveCharWidth * 18) / 2; //Get the x-axis starting point
  82.               yStart = (GetSystemMetrics(SM_CYSCREEN) -
  83.                           tm.tmHeight - tm.tmExternalLeading) / 2; //Get the y-axis starting point
  84.               xEnd = xStart + tm.tmAveCharWidth * 18; //Get the x-axis ending point 
  85.               yEnd = yStart + tm.tmHeight + tm.tmExternalLeading; //Get the y-axis ending point
  86.               hRgn = SetAniDesk(hdc, xStart, yStart, xEnd, yEnd); /*Call function SetAniDesk(handle of DC, x-starting point, 
  87.            y-starting point, x-ending point, y-ending) to get the clipping region,
  88.            you are not needed to select the region to the DC and must save the handle
  89.            for the next step*/
  90.               SetBkMode(hdc, TRANSPARENT); //Set Background mode to transparent
  91.               SetTextColor(hdc, RGB(iColor[0], iColor[1], iColor[2])); //Set the text color
  92.               DrawText(hdc, "Hello, Windows95 !", -1, &rect,
  93.               DT_SINGLELINE | DT_CENTER | DT_VCENTER);
  94.               ResetDisplayDC(hdc); //Call function ResetDisplay(hwndle of DC) to delete the Display DC
  95.               return 0;
  96.  
  97.         case WM_DESTROY:
  98.               ResetAniDesk(hRgn); /*Call function ResetAniDesk to delete
  99.            the clipping region, same as DeleteObject function*/
  100.               KillTimer(hwnd, 1);
  101.               PostQuitMessage(0);
  102.               return 0;
  103.         }
  104.     return DefWindowProc(hwnd, message, wParam, lParam);
  105.     }